/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dca.sistemascontrole.malhadecontrole;

/**
 *
 * @author Rafael
 */
public abstract class MalhaFechada extends MalhaDeControle {

    protected double kp, ki, kd, tw, gama;
    protected boolean usarFiltroDerivativo;
    protected boolean usarFiltroAntiWindup;
    public static final int P = 6;
    public static final int PI = 14;
    public static final int PD = 30;
    public static final int PID = 62;
    public static final int PI_D = 126;

    public MalhaFechada(double setpoint) {
        super();
        variaveisDeControle.setSetPoint(setpoint);
    }

    public void setTw(double tw) {
        this.tw = tw;
    }

    public void setGama(double gama) {
        this.gama = gama;
    }

    public void setKp(double kp) {
        this.kp = kp;
    }

    public void setKi(double ki) {
        this.ki = ki;
    }

    public void setKd(double kd) {
        this.kd = kd;
    }

    public void setUsarFiltroDerivativo(boolean usarFiltroDerivativo) {
        this.usarFiltroDerivativo = usarFiltroDerivativo;
    }

    public void setUsarFiltroAntiWindup(boolean usarFiltroAntiWindup) {
        this.usarFiltroAntiWindup = usarFiltroAntiWindup;
    }

    @Override
    public int getTipo() {
        return MALHA_FECHADA;
    }

    public double getSetpoint() {
        return variaveisDeControle.getSetPoint();
    }

    public void setSetpoint(double setpoint) {
        variaveisDeControle.setSetPoint(setpoint);
    }

    public static MalhaFechada criarMalhaFechada(int tipo, float setpoint, float kp, float ki, float kd, boolean usarFiltroDerivativo, boolean usarFiltroAntiWindup) {
        switch (tipo) {
            case P:
                return new ControladorP(setpoint, kp);
            case PI:
                return new ControladorPI(setpoint, kp, ki, usarFiltroAntiWindup);
            case PD:
                return new ControladorPD(setpoint, kp, kd, usarFiltroDerivativo);
            case PID:
                return new ControladorPID(setpoint, kp, ki, kd, usarFiltroDerivativo, usarFiltroAntiWindup);
            case PI_D:
                return new ControladorPI_D(setpoint, kp, ki, kd, usarFiltroDerivativo, usarFiltroAntiWindup);
        }

        return null;
    }
}
